//
//  Duck.m
//  Charles
//
//  Created by Charles on 2017/6/13.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "Duck.h"

@interface Duck ()

@property (strong,nonatomic) id<FlyBehavior> flyBehavior;
@property (strong,nonatomic) id<QuackBehavior>quackBehavior;

@end

@implementation Duck

- (void)performFly {
    [self.flyBehavior fly];
}

- (void)performQuack {
    [self.quackBehavior quack];
}

- (void)swim {
    NSLog(@"All ducks float, even decoys!");
}

- (void)setFlyBehavior:(id<FlyBehavior>)behavior {
    _flyBehavior = behavior;
}

- (void)setQuackBehavior:(id<QuackBehavior>)behavior {
    _quackBehavior = behavior;
}

@end

@implementation MallardDuck

- (instancetype)init {
    if (self = [super init]) {
        self.flyBehavior = [[FlyWithSwings alloc]init];
        self.quackBehavior = [[Quack alloc]init];
    }
    return self;
}

- (void)display {
    NSLog(@"I am a mallard Duck");
}

@end

@implementation ModelDuck

- (instancetype)init {
    if (self = [super init]) {
        self.flyBehavior = [[FlyNoWay alloc]init];
        self.quackBehavior = [[Quack alloc]init];
    }
    return self;
}

- (void)display {
    NSLog(@"I am model Duck");
}

@end

